<?php
namespace Home\Controller;
use Think\Controller;
class VideoController extends Controller{


	 public function videoArrange(){
       
        $videomodel=M('videos');
           // $coachmodel=M('coaches');
           // $this->coach=$coachmodel->order('coachid desc')->select(); 
             $clubmodel=M('coaches');
 $this->coach=$clubmodel->order('coachid desc')->select();
            $this->video=$videomodel->join('coaches ON coaches.coachid=videos.from')->select();
      //调用视图层显示结果
          $this->display();

  }
  public function addVideo(){

		$video = D('videos');
		$video->name = $_POST['name'];
		// $coach->coachpic = $_POST['coachpic'];
      if($_FILES["thumbnail"]["error"]==0||$_FILES["video"]["error"]==0){
        	$info=$this->upload();
        	// $info=$this->uploadV();
        	$video->video=$info["video"]["savename"];
        	$video->thumbnail=$info["thumbnail"]["savename"];
      	}else{
        	$this->error("必须上传图片"); 
      	}
      	
		$video->instruction = $_POST['instruction'];
		
		$video->from = $_POST['from'];
		// var_dump($video);
		$result = $video->add();
		if($result != flase){
			$this->success("添加视频成功！",U('Video/videoarrange'));//url
		}else{
			$this->error("录入信息有错！");
		}
	}
	 public function upload(){
    $upload = new \Think\Upload();// 实例化上传类
    $upload->maxSize   =     3145728000000 ;// 设置附件上传大小
    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','mp4');// 设置附件上传类型
    
    $upload->rootPath  =     './PUBLIC/photo/thumbnail/'; // 设置附件上传根目录
    $upload->autoSub=false;//关闭子目录，默认ture
    //$upload->savePath  =     ''; // 设置附件上传（子）目录,默认目录名为日期
    $info   =   $upload->upload();  // 上传文件 
    if(!$info) { 
    $this->error($upload->getError());    }
    else{
    return $info;   }                    
  }
   public function uploadV(){
    $uploadV = new \Think\Upload();// 实例化上传类
    $uploadV->maxSize   =     3145728 ;// 设置附件上传大小
    $uploadV->exts      =     array('jpg', 'gif', 'png', 'jpeg','mp4');// 设置附件上传类型
    
    $uploadV->rootPath  =     './PUBLIC/photo/thumbnail/'; // 设置附件上传根目录
    $uploadV->autoSub=false;//关闭子目录，默认ture
    //$upload->savePath  =     ''; // 设置附件上传（子）目录,默认目录名为日期
    $info   =   $uploadV->uploadV();  // 上传文件 
    if(!$info) { 
    $this->error($uploadV->getError());    }
    else{
    return $info;   }                    
  }
  public function play(){
    $id = $_GET['id'];
    $table = D('videos');
    $this->location = $table->where("videoid=".$id)->select();
    $this->display();
  }
         public function delete(){

        $id=I('get.videoid');
        $video=M("videos");
        $pic = $video->where("videoid=".$id)->field("thumbnail")->find();
        $res=$video->delete($id);
        unlink(realpath("./Public/photo/thumbnail/".$pic["thumbnail"]));
        if($res!=false){$this->success("删除成功");}
        else{$this->error("删除失败");}
    }
}

